<template>
  <div class="contact">
    <div class="ServiLiuc">
      <div class="ServiLiucTop">
        <img src="../assets/images/biaoti22@2x.png">
      </div>
      <div class="container">
    
        <div class="ServiLiucCon">
          <div class="ServiLiucConItem">
            <img src="../assets/images/1@2x.png">
            <p>1.填写入驻信息</p>
          </div>
          <div class="ServiLiucConItem">
            <img src="../assets/images/33@2x.png">
            <p>2.平台审核</p>
          </div>
          <div class="ServiLiucConItem">
            <img src="../assets/images/22@2x.png">
            <p>3.实名认证</p>
          </div>
          <div class="ServiLiucConItem">
            <img src="../assets/images/44@2x.png">
            <p>4.缴纳保证金</p>
          </div>
          <div class="ServiLiucConItem">
            <img src="../assets/images/5@2x.png">
            <p>5.发布活动</p>
          </div>
        </div>
    
        <!-- <div class="ConserMap">
          <div class="ConserMapIn" id="ConserMapIn"></div>
        </div> -->
      </div>
    
    </div>
    <div class="container">
      <!-- <div class="ctitle">商家入驻</div> -->
      <div class="elform">
        <el-form ref="form" :model="form" label-width="100px">
          <div class="logobox">
            <ImageUpload :key="key1" :limit="1" :type="1" @input="input" :isShowTip="false"></ImageUpload>
          </div>
          <el-form-item label="拍卖行名称：" style="margin-top: 20px;">
            <el-input v-model="form.shopname" placeholder="请输入店铺名称"></el-input>
          </el-form-item>
          <el-form-item label="申请人姓名：">
            <el-input v-model="form.name" placeholder="请输入申请人姓名"></el-input>
          </el-form-item>
          <el-form-item label="申请人手机：">
            <el-input v-model="form.phone" placeholder="请输入申请人手机"></el-input>
          </el-form-item>
          <el-form-item label="验证码：">
            <el-input v-model="form.msgcode" placeholder="请输入验证码">
              <template slot="append">
                <div v-if="sendshow==true" @click="send()">获取验证码</div>
                <div v-if="sendshow==false">{{num}}s</div>
              </template>
            </el-input>
          </el-form-item>
          <!-- <el-form-item label="银行：">
            <el-select v-model="form.banks" placeholder="请选择银行">
              <el-option
                @click.native="select(index)"
                v-for="(item, index) in options"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="银行卡号：">
            <el-input v-model="form.banknumber" placeholder="请输入银行卡号"></el-input>
          </el-form-item>
          <el-form-item label="收款人姓名：">
            <el-input v-model="form.bankname" placeholder="请输入收款人姓名"></el-input>
          </el-form-item>
          <el-form-item label="申请人身份证照片：">
            <ImageUpload :key="key2" :limit="1" :type="2" @input="input" :isShowTip="false"></ImageUpload>
            <ImageUpload :key="key3" :limit="1" :type="3" @input="input" :isShowTip="false"></ImageUpload>
            <ImageUpload :key="key4" :limit="1" :type="4" @input="input" :isShowTip="false"></ImageUpload>
          </el-form-item>
          <div class='textinfor-tishi'>
            <div class='textinfo-title' style="font-size: 14px;color: #606266;font-weight: 700;">买家佣金(买家在支付拍卖品时需额外支付的费用)</div>
            <div class='textinfo-ndes' style="color: #666;font-size: 12px;margin-bottom: 20px;">设置后,可以对每场拍卖进行单独启用</div>
          </div>
          <el-form-item label="最低：">
            <el-input v-model="form.lowfee" placeholder="(最低限制为10元)"></el-input>
          </el-form-item>
          <el-form-item label="费率：">
            <el-input v-model="form.feepercent" placeholder="可以精确到0.00%位"></el-input>
          </el-form-item>
          <el-form-item label="客服电话：">
            <el-input v-model="form.kefuphone" placeholder="请输入客服联系电话"></el-input>
          </el-form-item>
          <el-form-item label="客服二维码：">
            <ImageUpload  :key="key4" :type="5" @input="input" :isShowTip="false"></ImageUpload>
          </el-form-item> -->
          <div class="formbtn">
            <el-button type="primary" @click="onSubmit" style="background-color: rgb(178 12 12);border: none;width: 70%;height: 45px;">申请入驻</el-button>
          </div>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { apply, banklist, applyKf, sendMsg, upApplyPic } from '@/api/utils.js'
import mymd from "@/utils/jiami.js"
export default {
  name: '',
  components: {
  },
  props: [],
  data() {
    return {
      options: [],
      loadnum: 0,
      
      t: '',
      num: 60,
      sendshow: true,
      
      form: {
        shopname: '',
        name: '',
        phone: '',
        msgcode: '',
        bank: '',
        banknumber: '',
        bankname: '',
        lowfee: '',
        feepercent: '',
        kefuphone: ''
      },
      upload: [{file:''},{file:''},{file:''},{file:''},{file:''}],
      key1: new Date().getTime()+1,
      key2: new Date().getTime()+2,
      key3: new Date().getTime()+3,
      key4: new Date().getTime()+4,
      key5: new Date().getTime()+5
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getbanklist()
  },
  mounted() {},
  methods: {
    getbanklist() {
      var params={}
      banklist(params).then(res => {
        if (res.Code == 1) {
          this.options = res.list
        }
      })
    },
    select(index) {
      this.form.banks = this.options[index].name
    },
    // 发送验证码
    send() {
      if (this.form.phone == '') {
         this.$modal.msgError(`请先填写手机号码`);
        return
      }
      if (this.form.phone.length < 11) {
         this.$modal.msgError(`手机号填写错误`);
        return
      }
      this.sendRegisterCode()
    },
    sendRegisterCode() {
      var that = this
      let param = {
        phone: this.form.phone
      }
      sendMsg(param).then(res => {
        if (res.Code == 1) {
          var t =  setInterval(this.countDown, 1000)
          this.t = t
          this.sendshow = false
          this.$modal.msgSuccess('验证码发送成功')
        } else {
          this.$modal.msgError(res.msg)
        }
      })
    },
    countDown(){
      if (this.num == 1) {
        clearInterval(this.t)
        this.sendshow = true
        this.num = 60
      } else {
        this.num = this.num-1
      }
    },
    input(e) {
      this.upload[e.type-1].file = e.file
    },
    onSubmit() {
      let that = this
      var logo = this.upload[0].file
      var shopname = this.form.shopname
      var name = this.form.name;
      var phone = this.form.phone;
      var msgcode = this.form.msgcode;
      var bank = this.form.banks;
      var banknumber = this.form.banknumber;
      var bankname = this.form.bankname;
      var lowfee = this.form.lowfee;
      var feepercent = this.form.feepercent;
      var applyp = 1
      if (logo.length==0) {
        this.$modal.msgError(`请上传LOGO`);
        return false;
      }
      if (shopname == '') {
        this.$modal.msgError(`请输入拍卖行名称`);
        return false
      }
      if (name == '') {
        this.$modal.msgError(`请输入申请人姓名`);
        return false
      }
      if (phone == '') {
        this.$modal.msgError(`请输入申请人手机号`);
        return false
      }
      if (msgcode == '') {
        this.$modal.msgError(`请输入验证码`);
        return false
      }
      // if (bank == '') {
      //   this.$modal.msgError(`请选择银行`);
      //   return false
      // }
      // if (banknumber == '') {
      //   this.$modal.msgError(`请选择银行卡号`);
      //   return false
      // }
      // if (bankname.length <= 1) {
      //   this.$modal.msgError(`请输入正确的收款人姓名`);
      //   return false;
      // }
      // for (let i = 0; i < this.upload.length; i++) {
      //   if (this.upload[1].file == '') {
      //     this.$modal.msgError(`请上传身份证正面照`);
      //     return false;
      //   }
      //   if (this.upload[2].file == '') {
      //     this.$modal.msgError(`请上传身份证国徽面照片`);
      //     return false;
      //   }
      //   if (this.upload[3].file == '') {
      //     this.$modal.msgError(`请上传手持身份证照片`);
      //     return false;
      //   }
      // }
      // var regMoney = /^\d+(\.\d{0,3})?$/;
      // if (!lowfee) {
      //   this.$modal.msgError(`请输入最低佣金`);
      //   return false;
      // } else if (!regMoney.test(lowfee)) {
      //   this.$modal.msgError(`最低佣金只能输入两位小数`);
      //   return false;
      // } else if (parseInt(lowfee) < parseInt(10)) {
      //   this.$modal.msgError(`最低佣金不能小于10`);
      //   return false;
      // }
      // var regMoney = /^\d+(\.\d{0,3})?$/;
      // if (!feepercent) {
      //   this.$modal.msgError(`请输入费率`);
      //   return false;
      // } else if (!regMoney.test(feepercent)) {
      //   this.$modal.msgError(`费率只能输入两位小数`);
      //   return false;
      // } else if (parseFloat(feepercent) < parseFloat(1)) {
      //   this.$modal.msgError(`费率不能小于1`);
      //   return false;
      // } else if (parseFloat(feepercent) > parseFloat(100)) {
      //   this.$modal.msgError(`费率不能大于100`);
      //   return false;
      // }
      // var regphone = /^[\d -]*$/;
      // //console.log(aa.test(kefuphone))
      // if (kefuphone && !regphone.test(kefuphone)) {
      //   this.$modal.msgError(`客服电话只能输入数字和-`);
      //   return false;
      // }
      // if (this.upload[4].file == '') {
      //   this.$modal.msgError(`请上传客服二维码`);
      //   return false;
      // }
      this.$modal.loading("加载中...");

      let datauser = {
        type: applyp,
        shopname: shopname,
        name: name,
        phone: phone,
        msgcode: msgcode,
        // bank: bank,
        // bankname: bankname,
        // banknumber: banknumber,
        // feepercent: feepercent,
        // lowfee: lowfee,
        // kefuphone: kefuphone
      }
      let formData = new FormData()
      formData.append('jiamiformdatas', mymd.jiami(datauser)) // 额外参数
      formData.append('logo', logo)
      
      apply(formData).then(res => {
        if (res.Code == 1) {
          // this.getshopcode(res.id)
          this.key1 = new Date().getTime()+1
          this.key2 = new Date().getTime()+2
          this.key3 = new Date().getTime()+3
          this.key4 = new Date().getTime()+4
          this.key5 = new Date().getTime()+5
          this.loadnum = 0
          this.form = {
            shopname: '',
            name: '',
            phone: '',
            msgcode: '',
            bank: '',
            banknumber: '',
            bankname: '',
            lowfee: '',
            feepercent: '',
            kefuphone: ''
          },
          this.upload = [{file:''},{file:''},{file:''},{file:''},{file:''}]
          this.$modal.closeLoading();
          this.$modal.msgSuccess('提交成功');
        } else {
          this.$modal.closeLoading();
          this.$modal.msgError(res.msg);
        }
      })
    },
    getshopcode(e) {
      let datauser = {
        id: e
      }
      let formData = new FormData()
      formData.append('jiamiformdatas', mymd.jiami(datauser)) // 额外参数
      formData.append('shopcode', this.upload[4].file)
      
      applyKf(formData).then(res => {
        if (res.Code == 1) {
          this.loadnum = 0
          var pic1 = this.upload[1].file;
          var pic2 = this.upload[2].file;
          var pic3 = this.upload[3].file;
          this.uploadpic(pic1, 'id_card', e);
          this.uploadpic(pic2, 'id_card1', e);
          this.uploadpic(pic3, 'id_card2', e);
        } else {
          this.$modal.closeLoading();
          this.$modal.msgError(res.msg);
        }
      })
    },
    uploadpic(pic, name, applyid) {
      let datauser = {
        applyid: applyid
      }
      let formData = new FormData()
      formData.append('jiamiformdatas', mymd.jiami(datauser)) // 额外参数
      formData.append(name, pic)
      
      upApplyPic(formData).then(res => {
        if (res.Code == 1) {
          this.loadnum ++
          if (this.loadnum == 3) {
            this.key1 = new Date().getTime()+1
            this.key2 = new Date().getTime()+2
            this.key3 = new Date().getTime()+3
            this.key4 = new Date().getTime()+4
            this.key5 = new Date().getTime()+5
            this.loadnum = 0
            this.form = {
              shopname: '',
              name: '',
              phone: '',
              msgcode: '',
              bank: '',
              banknumber: '',
              bankname: '',
              lowfee: '',
              feepercent: '',
              kefuphone: ''
            },
            this.upload = [{file:''},{file:''},{file:''},{file:''},{file:''}]
            this.$modal.closeLoading();
            this.$modal.msgSuccess('提交成功');
          }
        } else {
          this.$modal.closeLoading();
          this.$modal.msgError(res.msg);
        }
      })
    }
  }
  
}
</script>

<style lang="scss" scoped>
  @import url("../assets/css/basic.css");
  @import url("../assets/css/media.css");
  .ServiEerLeftSite{
    padding: 20px 120px 20px 20px;
    box-sizing: border-box;
  }
  .ServiEerLeftSite p{
    font-size: 16px;
    line-height: 32px;
  }
  @media only screen and (min-width: 100px) and (max-width: 998px) {
    .ServiEerLeftSite{
      height: 44.3rem!important;
    }
    .ServiEerLeftSite{
      padding: 10px 10px 10px 10px;
      box-sizing: border-box;
    }
    .ServiEerLeftSite p{
      font-size: 12px;
      line-height: 20px;
    }
    .ServiEerLeftSite {
      height: 48.875rem!important;
    }
  }
  .contact{
    background-color: #f7f4ef;
  }
  .ctitle{
    font-size: 22px;
    font-weight: bold;
    text-align: center;
    margin: 50px 0;
  }
  .elform{
    width: 70%;
    margin: 0 auto;
  }
  ::v-deep .el-input-group__append{
    cursor: pointer;
    width: 111px;
    color: rgb(178 12 12);
    div{
      text-align: center;
    }
  }
  .formbtn{
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 30px 0 35px;
  }
</style>
<style>
  @media only screen and (min-width: 100px) and (max-width: 998px) {
    .elform{
      width: 100%!important;
    }
    .el-select{
      width: 100%;
    }
    .loadfirst2 .el-upload-list__item, .loadfirst2 .el-upload--picture-card{
      width: calc(100vw - 130px)!important;
      height: calc((100vw - 130px)/1.9)!important;
    }
    .formbtn button{
      width: 80%!important;
    }
    .ctitle{
      margin: 20px 0!important;
    }
  }
  .el-loading-spinner i, .el-loading-spinner .el-loading-text{
    color: #af8552!important;
  }
</style>